package com.ning.parking.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.ning.parking.domain.ParkingRecord;
import com.ning.parking.domain.VO.BillingResult;
import com.ning.parking.domain.VO.Pagination;
import com.ning.parking.domain.dto.ParkingRecordPageDto;
import com.ning.parking.service.ParkingRecordService;
import com.scsonic.framework.common.response.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @Author ChenN
 * @Date 2025/3/12 10:17
 * @Version 0.0.1
 **/
@Slf4j
@RestController
@RequestMapping("record")
@AllArgsConstructor
public class RecordController {

    private ParkingRecordService parkingRecordService;
    /**
     * 停车记录分页
     *
     * @return the 返回停车记录信息
     */
    @GetMapping("page")
    public R<Pagination<ParkingRecord>> page(ParkingRecordPageDto pageBase) {
        String carLicense = pageBase.getCarLicense();
        if (ObjectUtil.isEmpty(carLicense)){
            pageBase.setCarLicense(null);
        }
        log.debug("page-param:{}", JSONUtil.parseObj(pageBase));
        return R.ok(parkingRecordService.selectPage(pageBase));
    }

    /**
     * 查牌缴费功能
     * @param parkingRecord
     * @return
     */
    @GetMapping("billing")
    public R<ParkingRecord> billing(ParkingRecord parkingRecord) {
        log.debug("billing:{}", JSONUtil.parseObj(parkingRecord));
        return R.ok(parkingRecordService.billing(parkingRecord));
    }

    @PostMapping("order-pay")
    public R<ParkingRecord> orderPay(@RequestBody ParkingRecord parkingRecord) {
        log.debug("orderPay:{}", JSONUtil.parseObj(parkingRecord));
        return R.ok(parkingRecordService.orderPay(parkingRecord));
    }

    /**
     * 获取停车信息详情
     * @param recordId
     * @return
     */
    @GetMapping("record-details")
    public R<ParkingRecord> recordDetails(Long recordId) {
        return R.ok(parkingRecordService.recordDetails(recordId));
    }

}
